//package com.colorfruit.framework.rabbitmq.config;
//
//import com.colorfruit.framework.rabbitmq.component.RedisMqComponent;
//import com.colorfruit.framework.rabbitmq.model.BusinessMsg;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.beans.a_factory.InitializingBean;
//import org.springframework.beans.a_factory.annotation.Autowired;
//
//@Slf4j
//public abstract class BaseConsumer implements InitializingBean {
//
//    protected String consumerNameKey;
//
//    @Autowired
//    protected RedisMqComponent redisMqComponent;
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        consumerNameKey = this.getClass().getSimpleName() + RabbitMQConstant.TIMES;
//    }
//
////    @RabbitHandler
////    public void resolve(BusinessMsg<String, Object> businessMessage, Channel channel, Message message) {
////        try {
////            //设置这个消费者总消费次数+1
////            redisMqComponent.increment(RabbitMQConstant.TOTAL + consumerNameKey);
////            //获取消息ID
////            String  messageId = businessMessage.getBusinessId();
////            //消费队列没有消费过这个消息, 进行下一步
////            if(!alreadyConsume(messageId)) {
////                //将消费队列的值往后+一个消息ID
////                saveConsume(messageId);
////                //消费队列消费实际消息次数+1
////                redisMqComponent.increment(RabbitMQConstant.ACTUALLY + consumerNameKey);
////                //具体业务逻辑处理
////                concreteOperation(businessMessage);
////            }else {
////                log.warn("重复数据 = {}", messageId);
////            }
////            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
////        }catch (Exception e){
////            e.printStackTrace();
////        }
////    }
//    public abstract void resolve(BusinessMsg<String, Object> businessMessage, Channel channel, Message message);
//
//    public abstract void concreteOperation(BusinessMsg<String, Object> msg);
//
//    /**
//     * 将消费队列的值往后+一个消息ID
//     * @param messageId 需要往后加的消息ID
//     */
//    protected void saveConsume(String messageId) {
//        redisMqComponent.saveWithSet(this.consumerNameKey, messageId);
//    }
//
//    /**
//     * 判定消费队列中是否有这个消息ID
//     * 如果有, 表示该消息已经消费过, 无需再消费
//     * 如果没有,表示消息可以被消费
//     * @param messageId
//     * @return
//     */
//    protected boolean alreadyConsume(String messageId) {
//        return redisMqComponent.isContain(this.consumerNameKey, messageId);
//    }
//
//}
